﻿using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;
public class main : MonoBehaviour{

  public float range,ihorizm,ivertm;
  public Text textOutput0,textOutput1,textOutput2,textOutput3;
  public Text textOutputB1,textOutputB2;
  public int hgarbage1,vgarbage1;
  public int ubaxis,counter,counter2,counter3;
  public int keybd,keybd0,keybd1,keybd2,keybd3;
  public int xpos,ypos,xyspeed,xoff,yoff;
  public int xpos0,ypos0,xyspeed0,xoff0,yoff0;
  public int xpos1,ypos1,xyspeed1,xoff1,yoff1;
  public int xpos2,ypos2,xyspeed2,xoff2,yoff2;
  public int xpos3,ypos3,xyspeed3,xoff3,yoff3;
  public GameObject sprite0,sprite1,sprite2,sprite3,sprite4;
  public Sprite spritebm0,spritebm1,spritebm2,spritebm3;

  public Sprite[] spritebma = new Sprite[16];

  void Start(){
    counter=0;xyspeed=8;
    xpos=450;ypos=250;xoff=-360;yoff=-225;
    xpos0=400;ypos0=350;xoff0=-360;yoff0=-225;
    xpos1=480;ypos1=350;xoff1=-360;yoff1=-225;
    xpos2=560;ypos2=350;xoff2=-360;yoff2=-225;
    xpos3=640;ypos3=350;xoff3=-360;yoff3=-225;
    sprite4.GetComponent<SpriteRenderer>().sprite=sprite0.GetComponent<SpriteRenderer>().sprite;
    }

  void Update (){


    if (xpos<-0){xpos=0;}
    if (xpos>720){xpos=720;}
    if (ypos<0){ypos=0;}
    if (ypos>450){ypos=450;}

    keybd0=0;
    if (Input.GetKey(KeyCode.UpArrow)){keybd0+=4;ypos0-=xyspeed;}
    if (Input.GetKey(KeyCode.DownArrow)){keybd0+=8;ypos0+=xyspeed;}
    if (Input.GetKey(KeyCode.LeftArrow)){keybd0+=1;xpos0-=xyspeed;}
    if (Input.GetKey(KeyCode.RightArrow)){keybd0+=2;xpos0+=xyspeed;}

    keybd1=0;
    if (Input.GetKey(KeyCode.W)){keybd1+=4;ypos1-=xyspeed;}
    if (Input.GetKey(KeyCode.S)){keybd1+=8;ypos1+=xyspeed;}
    if (Input.GetKey(KeyCode.A)){keybd1+=1;xpos1-=xyspeed;}
    if (Input.GetKey(KeyCode.D)){keybd1+=2;xpos1+=xyspeed;}

    keybd2=0;
    if (Input.GetKey(KeyCode.T)){keybd2+=4;ypos2-=xyspeed;}
    if (Input.GetKey(KeyCode.G)){keybd2+=8;ypos2+=xyspeed;}
    if (Input.GetKey(KeyCode.F)){keybd2+=1;xpos2-=xyspeed;}
    if (Input.GetKey(KeyCode.H)){keybd2+=2;xpos2+=xyspeed;}

    keybd3=0;
    if (Input.GetKey(KeyCode.I)){keybd3+=4;ypos3-=xyspeed;}
    if (Input.GetKey(KeyCode.K)){keybd3+=8;ypos3+=xyspeed;}
    if (Input.GetKey(KeyCode.J)){keybd3+=1;xpos3-=xyspeed;}
    if (Input.GetKey(KeyCode.L)){keybd3+=2;xpos3+=xyspeed;}


    counter2=(counter/50)%1000;
    counter3=(counter/10)%4;

    //if (counter3==0){sprite4.GetComponent<SpriteRenderer>().sprite=sprite0.GetComponent<SpriteRenderer>().sprite;}
    //if (counter3==1){sprite4.GetComponent<SpriteRenderer>().sprite=sprite1.GetComponent<SpriteRenderer>().sprite;}
    //if (counter3==2){sprite4.GetComponent<SpriteRenderer>().sprite=sprite2.GetComponent<SpriteRenderer>().sprite;}
    //if (counter3==3){sprite4.GetComponent<SpriteRenderer>().sprite=sprite3.GetComponent<SpriteRenderer>().sprite;}

    //if (counter3==0){sprite4.GetComponent<SpriteRenderer>().sprite=spritebm0;}
    //if (counter3==1){sprite4.GetComponent<SpriteRenderer>().sprite=spritebm1;}
    //if (counter3==2){sprite4.GetComponent<SpriteRenderer>().sprite=spritebm2;}
    //if (counter3==3){sprite4.GetComponent<SpriteRenderer>().sprite=spritebm3;}

    sprite4.GetComponent<SpriteRenderer>().sprite=spritebma[3-counter3];

    textOutput0.text=xpos0.ToString("F0")+","+ypos0.ToString("F0")+","+keybd0.ToString("F0");
    textOutput1.text=xpos1.ToString("F0")+","+ypos1.ToString("F0")+","+keybd1.ToString("F0");
    textOutput2.text=xpos2.ToString("F0")+","+ypos2.ToString("F0")+","+keybd2.ToString("F0");
    textOutput3.text=xpos3.ToString("F0")+","+ypos3.ToString("F0")+","+keybd3.ToString("F0");

    textOutputB1.text=counter2.ToString("F0");
    textOutputB2.text=counter2.ToString("F0");

    sprite4.transform.position = new Vector2(xpos0+xoff0,(ypos0+yoff0)*-1);
    sprite1.transform.position = new Vector2(xpos1+xoff1,(ypos1+yoff1)*-1);
    sprite2.transform.position = new Vector2(xpos2+xoff2,(ypos2+yoff2)*-1);
    sprite3.transform.position = new Vector2(xpos3+xoff3,(ypos3+yoff3)*-1);


    counter+=1;

    }}





